﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MentorMap.Web;

namespace MentorMap
{
    public class UrlRewriteModule : MentorMapHttpModule
    {
        protected override void BeginRequest(object src, EventArgs e)
        {
            string path = Application.Request.Path.ToLower();

            if (path.Contains(".")) return;

            if (path.StartsWith("/"))
                path = path.Substring(1);

            IList<string> pieces = path.Split(new char[] { '/' });

            if (pieces.Count == 0) return;

            if (pieces.First().StartsWith("profile"))
                Application.Context.RewritePath("~/Account/Profile.aspx", false);
            else if (pieces.First().StartsWith("search"))
                Application.Context.RewritePath("~/Account/Search.aspx", false);
            else if (pieces.First().StartsWith("communication"))
                Application.Context.RewritePath("~/Communication.aspx", false);
        }
    }
}